import { useEffect } from "react";

const useEnter = (cb: Function) => {
    const handleEnter = (event) => {
        if (event.key === 'Enter') {
            cb && cb()
        }
    };
    useEffect(() => {
        document.addEventListener('keydown', handleEnter);

        return () => {
            document.removeEventListener('keydown', handleEnter);
        };
    }, [cb]);

}

export default useEnter